home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / JAVA_ALL / IDE / SUBARTIC / SUB_ARCT / TEST / STYLE_TE.JAV < prev    next >
Encoding:
Text File  |  1996-10-04  |  8.6 KB  |  300 lines

  1. /**
  2.  * This is an example program which tests out the new style based
  3.  * interactors.
  4.  */
  5. package sub_arctic.test;
  6.  
  7. import sub_arctic.lib.*;
  8. import sub_arctic.output.*;
  9. import sub_arctic.input.*;
  10. import sub_arctic.constraints.std_function;
  11.  
  12. import java.awt.Font;
  13. import java.awt.Point;
  14. import java.awt.Image;
  15. import java.net.URL;
  16. import java.net.MalformedURLException;
  17. import java.util.Vector;
  18.  
  19. /**
  20.  * This is an example program which tests out the new style based
  21.  * interactors.
  22.  * 
  23.  * @author Ian Smith 
  24.  * @version $Id: style_test.java,v 1.14 1996/10/03 19:46:51 hudson Exp $
  25.  */
  26. public class style_test extends interactor_applet implements callback_object {
  27.   String radio_stations[] = { "WREK", "WRAS","KFJC"};
  28.   /* first station tuned to is WREK */
  29.   String station="WREK";
  30.   /* the parent of the popup menu */
  31.   popup_parent pop_parent;
  32.   /* these menus are in the class so we can test for them in the callback */
  33.   /* make the interface */
  34.   menu toolkit_menu, version_menu,file_menu,edit_menu, help_menu;
  35.   public void build_ui(base_parent_interactor top) {
  36.     v_scrollbar vs;
  37.     h_scrollbar hs;
  38.     button b,logo;
  39.     URL url;
  40.     Image image;
  41.     loaded_image loaded_version;
  42.     scale sc;
  43.     text_toggle_collection c1,c2;
  44.     String choices[] = {"Blues","Industrial", "Techno", "Alternapop",
  45.              "Swing"};
  46.     String toolkit[] = {"Motif", "AWT", "SubArctic", "Fresco", "Artkit"};
  47.     String version[] = {"Billings", "Minneapolis", "Edmonton", "Nome"};
  48.     String file[] = {"New","Open","Save", "Quit"};
  49.     String edit[] = {"Cut", "Copy", "Paste", "Select All"};
  50.     String help[] = {"Little Help", "Less Help", "No Help", "Get Help"};
  51.  
  52.     Vector left=new Vector(),right=new Vector();
  53.     menu_button mb;
  54.     menubar mbar;
  55.     display_help_container dhc1, dhc2, dhc3;
  56.     int max,i;
  57.  
  58.     /* make the popup parent cover the whole thing */
  59.     pop_parent=new popup_parent(station);
  60.     pop_parent.set_w_constraint(std_function.offset(PARENT.W(), 0));
  61.     pop_parent.set_h_constraint(std_function.offset(PARENT.H(), 0));
  62.     top.add_child(pop_parent);
  63.     /*
  64.      * put in the menubar 
  65.      */
  66.     left.addElement("File");
  67.     left.addElement("Edit");
  68.     right.addElement("Help");
  69.     mbar=new menubar(left,right,100);
  70.     mbar.set_w_constraint(std_function.offset(PARENT.W(), 0));
  71.  
  72.       /* file menu */
  73.     file_menu=menu.create_text_menu(file,null,this);
  74.  
  75.     /* edit menu */
  76.     edit_menu=menu.create_text_menu(edit,null,this);
  77.  
  78.     /* help menu */
  79.     help_menu=menu.create_text_menu(help,null,this);
  80.  
  81.     mbar.associate_menu("File",file_menu);
  82.     mbar.associate_menu("Edit",edit_menu);
  83.     mbar.associate_menu("Help",help_menu);
  84.  
  85.     pop_parent.add_child(mbar);
  86.  
  87.     /* 
  88.        * vert scrollbar 
  89.        */
  90.     vs=new v_scrollbar(10,35,275,0,100,20,0.25,10,25,null);
  91.     /* 
  92.        *button with text 
  93.        */
  94.     b=new button(0,0,"Test Button",null);
  95.     dhc1=new display_help_container(b,"This is some help text");
  96.     dhc1.set_x(30);
  97.     dhc1.set_y(35);
  98.     /* 
  99.      * scale 
  100.      */
  101.     sc=new scale(0,0,200,0,100,10,25,null);
  102.     dhc3=new display_help_container(sc,"You can put display help on any object!");
  103.     dhc3.set_x(30);
  104.     dhc3.set_y(130);
  105.     /* 
  106.      * text toggle collection of radio buttons 
  107.      */
  108.     c1=new text_toggle_collection(radio_stations,true,60,this);
  109.     c1.set_x(30);
  110.     c1.set_y(160);
  111.     /* set the first object to be on */
  112.     c1.nth_toggle(0).set_cur_state(1);
  113.  
  114.     /* 
  115.        * next toggle collection (checkboxes) 
  116.        */
  117.     c2=new text_toggle_collection(choices,false,80,null);
  118.     c2.set_x(30);
  119.     c2.set_y(220);
  120.  
  121.     pop_parent.add_child(vs);
  122.     pop_parent.add_child(dhc1); 
  123.     pop_parent.add_child(dhc3);
  124.     pop_parent.add_child(c1);
  125.     pop_parent.add_child(c2);
  126.  
  127.     try {
  128.       loaded_version=manager.load_doc_image(this,"images/constrct.gif");
  129.     } catch (java.net.MalformedURLException e) {
  130.       showStatus("Problem loading the gif file");
  131.       return;
  132.     }
  133.     // make the new button and position it
  134.     logo=new button(loaded_version,null);
  135.     dhc2=new display_help_container(logo,"More help text from this one!");
  136.     dhc2.set_x(30);
  137.     dhc2.set_y(70);
  138.     pop_parent.add_child(dhc2);
  139.     /* 
  140.      * horizontal scrollbar 
  141.      */
  142.     hs=new h_scrollbar(10,320,300,0,100,20,0.25,10,25,null);
  143.     pop_parent.add_child(hs);
  144.  
  145.       /* 
  146.        * build the menus ... submenu first
  147.        */
  148.     version_menu=menu.create_text_menu(version,null,null);
  149.  
  150.  
  151.     /* 
  152.        * make the main menu 
  153.        */
  154.       /* find out the largest one */
  155.     max=text_menu_item.max_item_width(toolkit,null);    
  156.     /* make the menu */
  157.     toolkit_menu=new menu();
  158.     /* loop over the strings */
  159.     for (i=0;  i<toolkit.length; ++i) { 
  160.       if (i!=2) {
  161.     toolkit_menu.add_child(new text_menu_item(toolkit[i],max));
  162.       } else {
  163.     toolkit_menu.add_child(new pullright_menu_item(toolkit[i],
  164.                                null,max,
  165.                                version_menu));
  166.       }
  167.     }
  168.     /* 
  169.        * put the menu button in there 
  170.        */
  171.     mb=new menu_button("Toolkits",toolkit_menu);
  172.     mb.set_x(140);
  173.     mb.set_y(160);
  174.     pop_parent.add_child(mb);
  175.   }
  176.   /**
  177.    * This is the callback for the changing of the radio stations
  178.    * and reporting menu selections.
  179.    */
  180.   public void callback(
  181.     interactor       from_obj, 
  182.     event            evt,
  183.     int              callback_num, 
  184.     Object           callback_info) {
  185.  
  186.    interactor i;
  187.       /* is it from the toggle?*/
  188.    if (from_obj instanceof label_toggle) {
  189.      label_toggle lt=(label_toggle)from_obj;
  190.      station=lt.text();
  191.      pop_parent.set_value(station);
  192.    }
  193.    /* is it from a menu */
  194.    if (from_obj instanceof menu) {
  195.      i=(interactor)callback_info;
  196.      if (from_obj.equals(file_menu)) {
  197.        System.out.println("File Menu: " + file_menu.find_child(i));
  198.      }
  199.      if (from_obj.equals(edit_menu)) {
  200.        System.out.println("Edit Menu: " + edit_menu.find_child(i));
  201.      }
  202.      if (from_obj.equals(help_menu)) {
  203.        System.out.println("Help Menu: " + help_menu.find_child(i));
  204.      }
  205.    }
  206.   }
  207. }
  208. /**
  209.  * This is a little parent class which can pop up a menu.
  210.  */
  211. class popup_parent extends base_parent_interactor implements pressable {
  212.   /**
  213.    * Store the popup menu
  214.    */
  215.   menu popup;
  216.   /**
  217.    * This is where we keep all the strings in the menu, except the last one
  218.    */
  219.   String [] menu_items;
  220.   /**
  221.    * This is the current string to put last in the menu
  222.    */
  223.   String _value;
  224.   /* make one of these puppies with a default string */ 
  225.   public popup_parent(String s ) {
  226.     super(0,0,10,10);
  227.     _value=s;
  228.     popup=new menu();
  229.     menu_items=new String[5];
  230.     menu_items[0]="Cut";
  231.     menu_items[1]="Copy";
  232.     menu_items[2]="Paste";
  233.     menu_items[3]="Select All";
  234.   }
  235.   /**
  236.    * Build the popup menu 
  237.    */
  238.   public boolean press(event evt, Object not_used) {
  239.     int max;
  240.     top_level top=get_top_level();
  241.     /* get the point of the mouse press and convert to global coords */
  242.     Point p=new Point(evt.local_x(),evt.local_y());
  243.     p=local_to_global(p);
  244.  
  245.     /* delete all of popup's old children, if any */
  246.     while (popup.num_children()>0) {
  247.       popup.remove_child(0);
  248.     }
  249.     /* setup the array with our value */
  250.     menu_items[4]="Tuned to " + _value;
  251.     max=text_menu_item.max_item_width(menu_items,null);
  252.     for (int i=0; i<5; ++i) {
  253.       popup.add_child(new text_menu_item(menu_items[i],max));
  254.     }
  255.     /* put this menu in the toplevel */
  256.     top.add_child(popup);
  257.     popup.set_visible(true);
  258.     popup.set_x(p.x- (popup.w()/2));
  259.     popup.set_y(p.y);
  260.     /* force the coordinates to be in bounds */
  261.     if (popup.x()<0) popup.set_x(0);
  262.     if (popup.x()+ popup.w() > top.w()) {
  263.       popup.set_x(top.w()-popup.w());
  264.     }
  265.     /* y can't be negative... so only consider the bottom */
  266.     if (popup.y() + popup.h() > top.h()) {
  267.       popup.set_y(top.h()-popup.h());
  268.     }
  269.     menu.agent().set_focus_to(popup,evt,null);
  270.     return true;
  271.   }
  272.   /**
  273.    * Set the value of the last menu item.
  274.    */
  275.   public void set_value(String s) {
  276.     _value=s;
  277.   }
  278.   /**
  279.    * This never gets called because we make something the
  280.    * menu focus.
  281.    */
  282.   public boolean release(event evt, Object not_used) { return false;}
  283. }
  284. /*=========================== COPYRIGHT NOTICE ===========================
  285.  
  286. This file is part of the subArctic user interface toolkit.
  287.  
  288. Copyright (c) 1996 Scott Hudson and Ian Smith
  289. All rights reserved.
  290.  
  291. The subArctic system is freely available for most uses under the terms
  292. and conditions described in 
  293.   http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html 
  294. and appearing in full in the lib/interactor.java source file.
  295.  
  296. The current release and additional information about this software can be 
  297. found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
  298.  
  299. ========================================================================*/
  300.